/*
package com.jfzt;

import com.alibaba.fastjson2.JSONObject;
import com.jfzt.pojo.*;
import jakarta.servlet.http.HttpServletRequest;
import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.StringReader;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.Vector;

import static org.mockito.Mockito.when;

*/
/**
 * @author: shunpeng.hu
 * @date: 2024/1/8 11:01
 *//*

@SpringBootTest
public class SpringBootTest01 {

    @Test
    void testRecord() throws IOException {
        //1. 创建一个模拟的HttpServletRequest对象
        HttpServletRequest request = Mockito.mock(HttpServletRequest.class);

        String localAddr = request.getLocalAddr();
        System.out.println("localAddr:" + localAddr);

        KCRealmClient kcRealmClient = new KCRealmClient();
        RestTemplate restTemplate = new RestTemplate();
        UserPayload userPayload = new UserPayload();
        kcRealmClient.setKcRealm("Test");
        kcRealmClient.setKcAdmin("admin.test");
        kcRealmClient.setKcPassword("eyJhbGciOiJIUzI1NiJ9.eyJqdGkiOiI0ZWRlMGU0ZmVjMDk0MjM1YTJmMjk5MTgwNThkMDA0OSIsInN1YiI6ImpmenQudGVzdCIsImlzcyI6ImFkbWluIiwiaWF0IjoxNjk3MDA4OTE3LCJleHAiOjE3MTI1NjA5MTd9.vLr_K_QSAXonSTXkmjkeLzQVwjew-HG3tZiPhDALV3o");
        kcRealmClient.setKcClient("后端");
        userPayload.setUsername("shunpeng.hu");
        userPayload.setPassword("Hh295914");
        Map<String, Object> map = new HashMap<>(10);
        map.put("kcRealmClient",kcRealmClient);
        map.put("userPayload",userPayload);

        // 输出响应体
        ResponseEntity<KeycloakToken> response = restTemplate.postForEntity("http://192.168.212.39:9031/v2/api/login", map, KeycloakToken.class);
        KeycloakToken body = response.getBody();
        System.out.println("body.getName() = " + body.getName());
        System.out.println("body.getName() = " + body.getToken());

        //2. 设置模拟对象的返回值
        when(request.getMethod()).thenReturn("POST");
        when(request.getRequestURI()).thenReturn("/v2/api/loginLog");
        when(request.getQueryString()).thenReturn("param1=value1&param2=value2");
        when(request.getRemoteAddr()).thenReturn("192.168.212.39");
        when(request.getRemotePort()).thenReturn(9031);
        when(request.getProtocol()).thenReturn("HTTP/1.1");

        //3. 模拟请求头
        Vector<String> headerNames = new Vector<>();
        headerNames.add("Content-Type");
        Enumeration<String> headerEnumeration = headerNames.elements();
        when(request.getHeaderNames()).thenReturn(headerEnumeration);
        when(request.getHeader("Content-Type")).thenReturn("application/json");

        //4. 模拟请求体
        String requestBody = "{" +
                "  \"kcRealmClient\":{" +
                "    \"kcAdmin\":\"admin.test\"," +
                "    \"kcClient\":\"后端\"," +
                "    \"kcPassword\":\"eyJhbGciOiJIUzI1NiJ9.eyJqdGkiOiI0ZWRlMGU0ZmVjMDk0MjM1YTJmMjk5MTgwNThkMDA0OSIsInN1YiI6ImpmenQudGVzdCIsImlzcyI6ImFkbWluIiwiaWF0IjoxNjk3MDA4OTE3LCJleHAiOjE3MTI1NjA5MTd9.vLr_K_QSAXonSTXkmjkeLzQVwjew-HG3tZiPhDALV3o\"," +
                "    \"kcRealm\":\"Test\"" +
                "  }," +
                "  \"userPayload\":{" +
                "    \"username\":\"shunpeng.hu\"," +
                "    \"password\":\"xxx\"" +
                "  }" +
                "}";

        // 输出请求体
//        UserJsonVO keycloakTokenUser=  JSONObject.parseObject(requestBody, UserJsonVO.class);
//        System.out.println("keycloakTokenUser:" + keycloakTokenUser);
//        UserJsonVO keycloakTokenUser1=  JSONObject.parseObject(requestBody, UserJsonVO.class);
//        System.out.println("keycloakTokenUser1:" + keycloakTokenUser1);
//        System.out.println("requestBody:"+ requestBody);
        BufferedReader reader = new BufferedReader(new StringReader(requestBody));
        when(request.getReader()).thenReturn(reader);

        //5. 调用你的方法进行测试
        utils.record(request);
    }



}
*/
